import {ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy} from '@angular/router';

export class MyReUseStrategy implements RouteReuseStrategy{

  /**
   * 确定是否应该分离此路由（及其子树）以便以后重用
   * @param {ActivatedRouteSnapshot} route
   * @return {boolean}
   */
  shouldDetach(route: ActivatedRouteSnapshot): boolean {
    return false;
  }



  /**
   * 保存路由
   * @param {ActivatedRouteSnapshot} route
   * @param {DetachedRouteHandle | null} handle
   */

  store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void {
    console.log("当前路由 store"+route.url)
  }


  /**
   * 是否允许还原
   * @param {ActivatedRouteSnapshot} route
   * @return {boolean} true-允许还原
   */

  shouldAttach(route: ActivatedRouteSnapshot): boolean {
    return false;
  }
  /**
   * 从缓存中获取快照
   * @param {ActivatedRouteSnapshot} route
   * @return {DetachedRouteHandle | null}
   */
  retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle | null {
    return null;
  }


  /**
   * 进入路由触发, 判断是否为同一路由
   * @param {ActivatedRouteSnapshot} future
   * @param {ActivatedRouteSnapshot} curr
   * @return {boolean}
   */


  shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    return future.routeConfig==curr.routeConfig;
  }

}
